package com.eventx.service.def;

import com.eventx.bus.message.MessageData;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author: anrror
 **/
public class DefaultEventSource {

    Set<DefaultEventListenner> defaultEventListenners = new HashSet<>();

    public void addDefaultEventListenner(DefaultEventListenner defaultEventListenner){
        defaultEventListenners.add(defaultEventListenner);
    }


    public void clearAll(){defaultEventListenners.clear();}

    public void send(String eventName, MessageData messageData){
        Iterator<DefaultEventListenner> iterator = defaultEventListenners.iterator();
        while (iterator.hasNext()){
            DefaultEventListenner next = iterator.next();
            next.onEvent(eventName,messageData);
        }
    }



}
